
<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
  <meta name="description" content="xms">
  <meta name="author" content="xms">
  <link rel="icon" href="/content/favicon.ico">

  <title>自定义 - 实体 - 实体编辑</title>

  <!-- Bootstrap core CSS -->
  <link href="/content/css/bootstrap3.3.5/bootstrap.min.css" rel="stylesheet">

  <!-- Custom styles for this template -->
  <link href="/content/css/dashboard.css" rel="stylesheet">
  <link href="/content/css/font-awesome.min.css" rel="stylesheet">
  <link href="/content/customize/css/common.css" rel="stylesheet">
  <link href="/content/js/jquery-toast/jquery.toast.min.css" rel="stylesheet">
  <link id="themeLink" href="/content/css/theme/default.css" rel="stylesheet" />
  <!-- Bootstrap core JavaScript ================================================== -->
  <!-- Placed at the end of the document so the pages load faster -->
  <script src="/content/js/jquery.min.js"></script>
  <script src="/content/js/bootstrap.min.js"></script>
  <!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
  <script src="/content/js/ie10-viewport-bug-workaround.js"></script>
  <script src="/content/js/jquery.bootstrap.min.js"></script>
  <script src="/content/js/json2.js"></script>
  <script src="/content/js/xms.utility.js"></script>
  <script src="/content/js/jquery-ui-1.10.3/ui/jquery.ui.core.js"></script>
  <script src="/content/js/jquery-ui-1.10.3/ui/jquery.ui.widget.js"></script>
  <script src="/content/js/jquery-ui-1.10.3/ui/jquery.ui.mouse.js"></script>
  <script src="/content/js/jquery-ui-1.10.3/ui/jquery.ui.draggable.js"></script>
  <script src="/content/js/jquery-toast/jquery.toast.min.js"></script>
  <script src="/content/js/xms.jquery.js"></script>
  <script src="/content/js/xms.web.js"></script>
  <script src="/content/js/xms.metadata.js"></script>
  <script src="/content/js/md5.js" type="text/javascript"></script>
  <script src="/content/js/commonlabels.js"></script>
  <script src="/content/js/common/pagecontext.js"></script>
  <script src="/api/user/usercontext"></script>
  <script>
    jQuery(function () {
      Xms.Web.Loading();
      function aLinkClick(e) {

        if (currentKeycode != 17 && window.parent && window.parent.addToTab) {
          e.preventDefault();
          var tabNav = $('#customTabNav', parent.document).children('.iframe-link-linkitem.active');
          var textEl = tabNav.clone();
          $(".glyphicon-remove", textEl).remove();
          var label = textEl.text();
          textEl = $(this).clone();
          $("span", textEl).remove();
          label = label + '-' + textEl.text();
          var link = $(this).attr("href");
          var id = $.md5(link);
          Xms.Web.callParentMethod('addToTab', { id: id, label: label, link: link });
          return false;
        } else {
          //  currentKeycode = -99999;
          //  var link = $(this).attr("href");
          //  Xms.Web.OpenWindow(link);
        }

      }
      var currentKeycode = -99999;
      $("body").on("click.customizeLinkclick", 'a[href]a:not([href^="javascript:"])a:not([href^="#"])', function (e) {
        aLinkClick.call(this, e);
      });
    });
  </script>
  <style>
  body {
    padding: 0;
    margin: 0;
  }

  .table-responsive {
    max-height: 400px;
    overflow-y: auto;
  }

  .panel-default .panel-heading {
    background-color: white;
  }
</style>
</head>
<body>
<div class="" id="body">
  <div class="clearfix">
    <div class="col-md-12" id="main">
      <div class="" style="padding:5px;" id="renderBody">
        <!--main-->

        <div class="panel panel-default">
          <div class="panel-heading">
            <h3 class="panel-title">
              <a data-toggle="collapse"
                 href="#collapseTwo">
                <strong>实体编辑</strong>
              </a>
            </h3>
          </div>
          <div id="collapseTwo" class="panel-collapse collapse in">
            <div class="panel-body">
              <form action="/xms/api/schema/entity/update" method="post" id="editform" data-jsonajax="true" data-formdata="false" class="form-horizontal" role="form">
                <input data-val="true" id="EntityId" name="entityid" data-name="entityid" type="hidden" />
                <div class="form-group col-sm-12">
                  <label class="col-sm-2 control-label">名称</label>
                  <h4 class="col-sm-10 control-text">
                    <span class="form-control-static label label-info" data-name="name"></span>
                  </h4>
                </div>
                <div class="form-group col-sm-12">
                  <label class="col-sm-2 control-label" for="LocalizedName">显示名称</label>
                  <div class="col-sm-10">
                    <input class="form-control required" data-val="true" id="LocalizedName" name="localizedname" data-name="localizedname" type="text" />
                  </div>
                </div>
                <div class="form-group col-sm-12">
                  <label class="col-sm-2 control-label" for="EntityMask1">授权级别</label>
                  <div class="col-sm-10">
                    <label class="checkbox-inline">
                      <input checked="checked" class="required" data-val="true" id="EntityMask1" name="entitymask" data-name="entitymask" type="radio" value="1" /> 按用户
                    </label>
                    <label class="checkbox-inline">
                      <input class="required" id="EntityMask2" name="entitymask" data-name="entitymask" type="radio" value="4" /> 按组织
                    </label>
                  </div>
                </div>
                <div class="form-group col-sm-12">
                  <label class="col-sm-2 control-label" for="AuthorizationEnabled1">权限控制</label>
                  <div class="col-sm-10">
                    <label class="checkbox-inline">
                      <input checked="checked" class="required" data-val="true" id="AuthorizationEnabled1" name="authorizationenabled" data-name="authorizationenabled" type="radio" value="true" /> 启用
                    </label>
                    <label class="checkbox-inline">
                      <input class="required" id="AuthorizationEnabled0" name="authorizationenabled" data-name="authorizationenabled" type="radio" value="false" /> 禁用
                    </label>
                  </div>
                </div>
                <div class="form-group col-sm-12">
                  <label class="col-sm-2 control-label" for="LogEnabled1">日志监控</label>
                  <div class="col-sm-10">
                    <label class="checkbox-inline">
                      <input class="required" data-val="true" id="LogEnabled1" name="logenabled" data-name="logenabled" type="radio" value="true" /> 启用
                    </label>
                    <label class="checkbox-inline">
                      <input checked="checked" class="required" id="LogEnabled0" name="logenabled" data-name="logenabled" type="radio" value="false" /> 禁用
                    </label>
                  </div>
                </div>
                <div class="form-group col-sm-12">
                  <label class="col-sm-2 control-label" for="DuplicateEnabled1">重复检测</label>
                  <div class="col-sm-10">
                    <label class="checkbox-inline">
                      <input class="required" id="DuplicateEnabled1" name="duplicateenabled" data-name="duplicateenabled" type="radio" value="true" /> 启用
                    </label>
                    <label class="checkbox-inline">
                      <input checked="checked" class="required" id="DuplicateEnabled0" name="duplicateenabled" data-name="duplicateenabled" type="radio" value="false" /> 禁用
                    </label>
                  </div>
                </div>
                <div class="form-group col-sm-12">
                  <label class="col-sm-2 control-label" for="WorkFlowEnabled1">启用审批流</label>
                  <div class="col-sm-10">
                    <label class="checkbox-inline">
                      <input class="required" data-val="true" id="WorkFlowEnabled1" name="workflowenabled" data-name="workflowenabled" type="radio" value="true" /> 启用
                    </label>
                    <label class="checkbox-inline">
                      <input checked="checked" class="required" id="WorkFlowEnabled0" name="workflowenabled" data-name="workflowenabled" type="radio" value="false" /> 禁用
                    </label>
                  </div>
                </div>
                <div class="form-group col-sm-12 hide">
                  <label class="col-sm-2 control-label" for="BusinessFlowEnabled1">启用业务流</label>
                  <div class="col-sm-10">
                    <label class="checkbox-inline">
                      <input class="required" data-val="true" id="BusinessFlowEnabled1" name="businessflowenabled" data-name="businessflowenabled" type="radio" value="true" /> 启用
                    </label>
                    <label class="checkbox-inline">
                      <input checked="checked" class="required" id="BusinessFlowEnabled0" name="businessflowenabled" data-name="businessflowenabled" type="radio" value="false" /> 禁用
                    </label>
                  </div>
                </div>
                <div class="form-group col-sm-12">
                  <label class="col-sm-2 control-label">分组</label>
                  <div class="col-sm-10 required" id="entitygroups">
                  </div>
                </div>
                <div class="form-group col-sm-12">
                  <label class="col-sm-2 control-label" for="Description">描述</label>
                  <div class="col-sm-10">
                        <textarea class="form-control" id="Description" name="description" data-name="description" row="5">
</textarea>
                  </div>
                </div>
                <div class="form-group col-sm-12 text-center" id="form-buttons">
                  <button type="submit" class="btn btn-primary"><span class="glyphicon glyphicon-saved"></span> 保存</button>
                  <button type="reset" class="btn btn-default"><span class="glyphicon glyphicon-refresh"></span> 重置</button>
                  <button type="button" class="btn btn-warning" id="delBtn" onclick="delEntity()"><span class="glyphicon glyphicon-trash"></span> 删除</button>
                </div>
              </form>
            </div>
          </div>
        </div>

      </div>
      <nav class="navbar navbar-default navbar-fixed-bottom hide" role="navigation" id="body-footer">
        <div class="container">
          <div class="navbar-form navbar-right" id="body-footer-content">
          </div>
        </div>
      </nav>
    </div>
  </div>
</div>

<script src="/content/js/jquery.form.js"></script>
<script src="/content/js/jquery-validate/jquery.validate.min.js"></script>
<script src="/content/js/jquery-validate/localization/messages_zh.min.js"></script>
<script src="/content/js/xms.fillform.js"></script>
<script>
  var entityGroups = [];
  var model = $.urlParamObj(location.href);
  $('#ribbonbuttonid').val(model.id);
  function loadData() {
    Xms.Web.GetJson('/api/schema/entity/getbyid/' + model.id, null, function (res) {
      var data = res.Content;
      if(!data) return;
      $('#editform').fillForm(data);
      if(data.entitygroups)
        entityGroups = JSON.parse(data.entitygroups);
    }, null, false, 'GET', true);
  }
  $(function () {
    loadData();
    //表单验证
    Xms.Web.Form($("#editform"), function (response) {
      if (response.IsSuccess) {
        Xms.Web.Toast(response.Content || response.ErrorMessage, true);
        Xms.Web.Event.publish('refreshtree');
        return;
      }
      Xms.Web.Alert(false, response.Content);
    });
    bindEntityGroups();
  });
  function bindEntityGroups() {
    Xms.Ajax.GetJson('/api/data/retrieve/all/entitygroup/name/name:asc', null, function (response) {
      var data = Xms.Web.GetAjaxResult(response);
      var $container = $('#entitygroups');
      $(data.content).each(function (i, n) {
        var isChecked = $.inArray(n.entitygroupid, entityGroups) >= 0;
        $container.append('<label class="col-sm-3 col-xs-3"><input type="checkbox" name="entitygroupid" value="'+n.entitygroupid+'" '+(isChecked ? 'checked':'')+' />'+n.name+'</label>');
      });
    });
  }
  function delEntity() {
    Xms.Web.Del($('#EntityId').val(), 'api/schema/entity/deletebyid', false, function (response) {
      if (response.IsSuccess) {
        Xms.Web.Event.publish('refreshtree');
        location.href = 'create';
        return;
      }
      Xms.Web.Alert(false, response.ErrorMessage);
    }, null, '删除后相关数据也将一并删除，请提前备份数据', true, {

      content: '<div class="form-group"><h3 style="color:red;"><label class="checkbox-inline"><input class="" style="margin:0; font-size:12px;" id="anddeltable" type="checkbox" value="true" checked="checked" /><span style="font-size:18px;" class="pl-5">同时删除表？</span></label></h3></div>',
      checkOk: function (opts) {
        var ckb = $('#anddeltable').prop('checked');
        opts.postdata = {
          deletetable: ckb
        }

        return true;
      }
    });
  }
</script>

</body>
</html>